package controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.admin;
import common.BaseServlet;
import service.adminDAO;

/**
 * Servlet implementation class htLoginServlet
 */
@WebServlet("/gzh-htLogin")
public class htLoginServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	adminDAO aDao=new adminDAO();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public htLoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    public String basefun(HttpServletRequest request, HttpServletResponse response) {
		return "f:htjsp/gzh-htLogin";
	}
    public void htLogin (HttpServletRequest request, HttpServletResponse response) {
    	String name=request.getParameter("adminID");
    	String psw=request.getParameter("adminPassword");
    	admin admin=aDao.htLogin(name, psw);
    	String tel=aDao.getTel(name, psw);
    	int whether=admin.getWhether_position();
    	int permission=admin.getPermission();
    	HttpSession session=request.getSession();
    	session.setAttribute("permission", permission);
    	List<admin> adminMsg=aDao.getAdminByPhone(tel);
    	session.setAttribute("adminMsg",adminMsg);
    	PrintWriter out;
    	try {
			out=response.getWriter();
			if (admin!=null) {
				if (whether==1) {
					session.setAttribute("tel", tel);
					out.print("ok");
				} else{
					out.print("fail");
				}
			} 
		} catch (Exception e) {
			// TODO: handle exception
		}
    }

}
